package top.xin1901.j2ecd.service.impl;

import org.springframework.stereotype.Service;
import top.xin1901.j2ecd.beans.Permission;
import top.xin1901.j2ecd.dao.PermissionDao;
import top.xin1901.j2ecd.service.PermissionService;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author HeYunjia
 */

@Service
public class PermissionServiceImpl implements PermissionService {

    @Resource
    PermissionDao permissionDao;

    @Override
    public Permission insertOne(Permission permission) {

        permission.setGmtCreate(new Date());
        permission.setGmtModified(new Date());

        int insert = permissionDao.insert(permission);

        return insert == 1
                ? permissionDao.selectByPrimaryKey(permission.getPermissionId())
                : null;
    }

    @Override
    public Integer deleteOne(Long permissionId) {
        return null;
    }

    @Override
    public Permission updateOne(Permission permission) {
        permission.setGmtModified(new Date());
        return permissionDao.updateByPrimaryKey(permission) == 1 ? permission : null;
    }

    @Override
    public List<Permission> selectAll() {
        return permissionDao.selectAll();
    }

    @Override
    public Permission selectOne(Long permissionId) {
        return permissionDao.selectByPrimaryKey(permissionId);
    }

    @Override
    public List<Permission> selectByTypeId(Long typeId) {
        return permissionDao.selectByTypeId(typeId);
    }
}
